﻿<!--#include file="../inc/easp/easp.asp"-->
<!--#include file="../inc/conn1.asp"-->
<!--#include file="../inc/checklogin.asp"-->
<!--#include file="../inc/easyide.asp"-->
<% CheckLogin("../index.asp") %>
<%
	If Session("Authority")<>"0" Then
		Response.Write "<script type=""text/javascript"">top.location.href='../main.asp';</script>"
	end if				
%>

<%
    dim operate,relt,timepath
    
    operate = Easp.Get("op")
  
    dim gid,result,groupname,grouppath,rsgroup ,uid
    
     If (Cstr(session("ID"))<>"") Then 
       uid=session("ID")
    End if
    
    IF request.QueryString("action")="delete" Then
      
        gid=request.QueryString("gid")

        if(gid<>"") then
        
            result = Easp.db.DeleteRecord("group", "ID:" &gid)   
            
            result = Easp.db.DeleteRecord("country", "g_id:" &gid)  
            
            If result<>0 Then  
                Response.write("<Script language=JavaScript>alert('Delete Data Sucess!');</Script>") 
                
            else
                Response.write("<Script language=JavaScript>alert('Delete Data Fail!');</Script>") 
            End If  
            Response.Redirect "group.asp"
        End if
        
    ElseIf (request.QueryString("action")="add") then
        
         groupname=request.form("txtGroupName")
        
         grouppath=request.form("txtGroupPath")
         
         timepath=request.form("txtTimePath")
        
         '插入组表
         relt=Easp.db.AddRecord("Group",Array("GroupName:"&groupname,"SavePath:"&grouppath,"TimePath:"&timepath))
         
         '查询刚插入的组号
         'rsgroup=Easp.db.GetRecordBySQL("Select max(ID) as gid  From [Group]")
         
         'if Not Easp.IsN(rsgroup) Then
            ' gid=rsgroup("gid")
         'end if
         
         'response.write("<Script language=JavaScript>alert('gid:"&gid&"');</Script>")
         'response.write("<Script language=JavaScript>alert('uid:"&uid&"');</Script>")
         '插入组用户关系表
        ' relt=Easp.db.AddRecord("UserGroup",Array("UserID:"&uid,"GroupID:"&gid))
  
	    If relt<>0 Then
			 response.write("<Script language=JavaScript>alert('Add  Succeed');</Script>")
		else
			response.write("<Script language=JavaScript>alert('Add  Failed');</Script>")
		End If
		
		Response.Redirect "Group.asp"
	ElseIf request.QueryString("action")="edit" then
        
        groupname=request.form("txtGroupName")
        grouppath=request.form("txtGroupPath")
        timepath=request.form("txtTimePath")
        gid=CInt(request.form("gid"))
        
        'response.write("<Script language=JavaScript>alert('groupname:"&groupname&"');</Script>")
        'response.write("<Script language=JavaScript>alert('grouppath:"&grouppath&"');</Script>")
        'response.write("<Script language=JavaScript>alert('gid:"&gid&"');</Script>")
        
        relt=Easp.db.UpdateRecord("Group","ID="&gid,Array("GroupName:"&groupname,"SavePath:"&grouppath,"TimePath:"&timepath))
		         
	    If relt<>0 Then
			 response.write("<Script language=JavaScript>alert('Edit  Succeed');</Script>")
		else
			 response.write("<Script language=JavaScript>alert('Edit  Failed');</Script>")
		End If
		
		Response.Redirect "Group.asp"
    End if 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        <%
	Easp.w "Group Detail"
        %>
    </title>
    <link rel="stylesheet" type="text/css" href="../css/theme.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />

    <script type="text/javascript">
	var StyleFile = "theme" + document.cookie.charAt(6) + ".css";
	document.writeln('<link rel="stylesheet" type="text/css" href="../css/' + StyleFile + '">');
	
	 function GoBack()
    {
        top.location.href="index.asp";
    }
    
    function deleteGroup(gid)
	  {
		  if(confirm("Are you sure?"))
		  {
			    top.location.href = "Group.asp?action=delete&gid=" + gid;
		  }
		  else
		  {
			
		  }
	  }
    </script>

    <!--[if IE]>
<link rel="stylesheet" type="text/css" href="css/ie-sucks.css" />
<![endif]-->
</head>
<body>
    <div id="container">
        <div id="header">
            <div id="divAccount" style="float: right;">
                <a href="../user/account.asp" style="color: white">Account</a>&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="../inc/logout.asp" style="color: white">Logout</a>
            </div>
            <h2>
                <%
        Easp.w "Group Detail"
                %>
            </h2>
            <div id="topmenu">
                <ul>
                    <li><a href="../main.asp">Home</a></li>
                    <li class="current"><a href="#">Country</a></li>
                    <li><a href="../holiday/index.asp">Holiday</a></li>
                    <li><a href="../Times/index.asp">Times</a></li>
                    <li><a href="../wallboard/index.asp">WallBoard</a></li>
                    <%
				   If Session("Authority")="0" Then 
				       Response.Write("<li><a href='../user/index.asp'>User</a></li>")
				   End if
                    %>
                    <li>
                        <% If Session("Passed")=true Then %>
                        <a href="../inc/logout.asp">Logout</a><% End If %></li>
                </ul>
            </div>
        </div>
        <div id="top-panel">
            <div id="panel">
                <ul>
                    <li><a href="index.asp" class="goback">GoBack</a></li>
                </ul>
            </div>
        </div>
        <div id="wrapper">
            <div id="content">
                <form name="myform" action="index.asp" method="post">
                    <div id="box">
                        <div id="rightnow">
				                  <h3 class="reallynow"> 
					                  <span>Group</span>					    
					                  <a href="AddGroup.asp" class="add">Add Group</a> 
					                  <br />
				                  </h3>				
			                  </div>
                        <table width="100%" style="text-align: center;">
                            <p>
                                <%
                                dim epage
                                dim i
                                set rsgroup= Easp.db.GetRecordBySQL("SELECT Group.ID, Group.GroupName ,Group.SavePath,Group.TimePath  FROM [Group]")  
                
                                
                                If Not Easp.IsN(rsgroup) Then
                                    rsgroup.pagesize=20
                                    
                                    if request("page")<>"" then
                                      epage=cint(request("page"))
                                       if epage<1 then epage=1
                                       if epage>rsgroup.pagecount then epage=rsgroup.pagecount
                                    else
                                    epage=1
                                    end if
                                    rsgroup.absolutepage=epage
                                
                                end if
                                %>
                                <%   If Not Easp.IsN(rsgroup) Then%>
                                <table border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" width="80%" align="center">
                                    <tr bgcolor="#FFFFFF" align="center">
                                        <th>
                                            Code</th>
                                        <th>
                                            Group</th>
                                        <th>
                                            HolidayPath</th>
                                            <th>
                                            TimePath</th>
                                        <th>
                                            Delete</th>
                                        <th>
                                            Edit</th>
                                    </tr>
                                    <% end if%>
                                    <%
                                    
                                    If Not Easp.IsN(rsgroup) Then
                                for i=0 to rsgroup.pagesize-1
                                if rsgroup.bof or rsgroup.eof then exit for
                                    %>
                                    <tr bgcolor="#FFFFFF" align="center">
                                        <td style="height:15px">
                                            <%=rsgroup(0).value%>
                                        </td>
                                        <td style="height: 15px">
                                            <%=rsgroup(1).value%>
                                        </td>
                                         <td style="height:20px">
                                            <%=rsgroup(2).value%>
                                        </td>
                                         <td style="height:20px">
                                            <%=rsgroup(3).value%>
                                        </td>
                                        <td style="height: 10px">
                                            
                                            <%="<a href='javascript:deleteGroup(" & rsgroup(0).value & ")'>Delete</a>" %>
                                        </td>
                                        <td style="height: 10px">
                                            <a href="EditGroup.asp?action=edit&gid=<%=rsgroup(0).value%> &groupname=<%=rsgroup(1).value%>&savepath=<%=rsgroup(2).value%>&timepath=<%=rsgroup(3).value%>">
                                                Edit</a>
                                        </td>
                                    </tr>
                                    <%
                                rsgroup.movenext()
                                next
                                end if
                                    %>
                            </p>
                            <tbody>
                            </tbody>
                        </table>
                        <div id="pager">
                            <%
                                
                                if Not Easp.IsN(rsgroup) Then
                                    Easp.w "<p align='center'>"
                                    Easp.w "<a href='group.asp'>First</a> <a href='group.asp?page="&epage-1&"'>Previous</a>"
                                    Easp.w "<a href='group.asp'>First</a>  <a href='group.asp?page="&epage-1&"'>Previous</a>"
                                   
                                    'Easp.w "<a href='index.asp?page="%epage+1&"'>Next</a>&nbsp; <a href='index.asp?page="&rscountry.pagecount&"'>Last</a>"
                                    Easp.w "</p>"
                                    
                                    Easp.w "<p align='center'>"
                                    Easp.w "Now at"
                                    Easp.w epage
                                    Easp.w "page ,Totle"
                                    Easp.w rsgroup.pagecount
                                    Easp.w "page"
                                    Easp.w "</p>"
      
                                    Easp.db.C(rsgroup) 
                                 else 
                                 
                                    Easp.w "<h4> Has no data!</h4>"
                                 end if
                                  
                            %>
                            <%
					    'If Session("Authority")="0" Then
					      'Easp.wc "<input name='add' type='button' class='btn' value='add' onclick=""top.location.href='AddGroup.asp';""/>"
						'End if
                            %>
                        </div>
                    </div>
                </form>
            </div>
            <!--#include file="../inc/footer.asp" -->
</body>
</html>
